package com.yonyou.pmclouds.safetypatrol.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.picture.entity.PictureVO;
import com.yonyou.pmclouds.picture.rmiitf.PictureRemoteService;
import com.yonyou.pmclouds.safetypatrol.entity.SafetypatrolDetailVO;
import com.yonyou.pmclouds.safetypatrol.mapper.SafetypatrolDetailMapper;
import com.yonyou.pmclouds.safetypatrol.mapper.SafetypatrolMapper;
import com.yonyou.pmclouds.safetypatrol.service.rmiitf.SafetypatrolDetailQuery;
import org.apache.commons.collections.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;


@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = SafetypatrolDetailQuery.class)
public class SafetypatrolDetailQueryImpl implements SafetypatrolDetailQuery {

    @Resource
    private SafetypatrolDetailMapper safetypatrolDetailMapper;
    @Resource
    private SafetypatrolMapper safetypatrolMapper;
    @Resource
    private PictureRemoteService pictureRemoteService;

    @Override
    public List<SafetypatrolDetailVO> queryById(String pk_entity) throws BusinessException {

        List<SafetypatrolDetailVO> safetypatrolDetailVOList =safetypatrolDetailMapper.findById(pk_entity);
        setExamplePics(safetypatrolDetailVOList);

        return safetypatrolDetailVOList;
    }

    @Override
    public Integer queryCount(String pk_entity) throws BusinessException {
        List<SafetypatrolDetailVO> byId = safetypatrolDetailMapper.findById(pk_entity);
        if (CollectionUtils.isNotEmpty(byId)) {
            return byId.size();
        }
        return null;
    }

    @Override
    public List<SafetypatrolDetailVO> queryByPKandcode(String pkSafetypatrol) {
       List<SafetypatrolDetailVO> vos = safetypatrolDetailMapper.queryByPKandcode(pkSafetypatrol);
       if (CollectionUtils.isEmpty(vos)){
           return null;
       }
        return vos;
    }

    //查询每条检查标准对应的数量
//    @Override
//    public List<SafetypatrolDetailVO> selectDetailCount(List<String> needPKs) {
//        List<SafetypatrolDetailVO> safetypatrolDetailVOList = safetypatrolDetailMapper.selectListSafeVO(needPKs);
//        return safetypatrolDetailVOList;
//    }

    private void setExamplePics(List<SafetypatrolDetailVO> safetypatrolDetailVOList) throws BusinessException {
        if (safetypatrolDetailVOList!=null&&safetypatrolDetailVOList.size()>0){
            for (SafetypatrolDetailVO safetypatrolDetailVO : safetypatrolDetailVOList) {
                PictureVO[] pictureVOS = pictureRemoteService.queryExamplePicsByEntity(safetypatrolDetailVO.getPkSafetypatroldetail());
                safetypatrolDetailVO.setExamplePictures(pictureVOS);
            }
        }
    }


}
